
function $(selector){
	return document.querySelector(selector);
}
function $$(selector){
	return document.querySelectorAll(selector);
}

var body = $("body"),
    proHeader = $("#J_proHeader");
    
//body.scrollTop
var body_top ;

/**页面进入之后立即执行的动画**/
var proTop = proHeader.offsetTop,
    proSpeed = proTop/30;
var t = setInterval(function(){
	body_top = body.scrollTop;
	if(body_top>proTop){
		clearInterval(t);
		return;
	}
	body.scrollTop += proSpeed;
},16);


var scrollFun = {
	
	//添加类名方法
	addClass:function(sel,className){
		sel.classList.add(""+className);
	},
	//移除类名方法
	removeClass:function(sel,className){
		sel.classList.remove(""+className);
	},
	//获取自身高度
	getoffHeight : function(sel){
		return $(""+sel).offsetHeight;
	},
	//
}


//鼠标滑动到显示页面才动画加载
var nav_bar = $(".nav-bar-hidden"),
    mi_index = $(".mi6-index");

var indexTop;
var i = 0;
document.body.onscroll = function(){
	body_top = body.scrollTop;
	
	/**mi6标题**/
	indexTop = mi_index.offsetTop;
	//height
	var height = scrollFun.getoffHeight(".section-design"),
	    height_top = scrollFun.getoffHeight(".section-top"),
	    height_pho = scrollFun.getoffHeight(".section-photos"),
	    height_footer = scrollFun.getoffHeight(".section-footer");
	    
	console.log(height_top,height_footer);
	switch (true){
		//导航栏fix
		case body_top>=indexTop:
			scrollFun.addClass(nav_bar,"nav-fix");
			break;
		case body_top<=indexTop:
		    scrollFun.removeClass(nav_bar,"nav-fix");
		    break;
		    
	}
}


function preload(bTop,inTop,i){
	var section = $$(".section");
	switch (true){
		case i==1:
		    if(bTop>(inTop+420)){
				scrollFun.addClass(section[1],"is-visible");
				scrollFun.addClass(section[2],"preload");
			}	
			break;
		case i>1&&i!=4&&i!=11:
			if(bTop>(inTop+840+i*1/2*900)){
				scrollFun.addClass(section[i],"is-visible");
				scrollFun.addClass(section[i+1],"preload");
			}
			break;
		case i==4:
			scrollFun.addClass(section[4],"is-visible");
			scrollFun.addClass(section[5],"preload");
			break;	
	}
}

document.onclick = function(){
	
}
